package com.cn.action;


import com.cn.entity.UserEntity;
import com.cn.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

public class LoginAction implements ActionInterface {
    @Override
    public String execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        String uphone = request.getParameter("phone");
        String upassword = request.getParameter("password");
        UserEntity userEntity = new UserEntity();
        userEntity.setPassword(upassword);
        userEntity.setPhone(uphone);
        UserService us = new UserService();
        UserEntity userEntity1 = new UserEntity();

        userEntity1 = us.queryOne(userEntity, "login");
        request.removeAttribute("login");
        request.removeAttribute("loginerr");
        if (userEntity1 != null) {
            request.getSession().setAttribute("userent", userEntity1);
            request.setAttribute("login", "login");
            return "login.jsp";
        } else {
            request.setAttribute("loginerr", "错误信息显示");
            return "login.jsp";
        }
    }
}
